package com.lizongbo.seotijian.rules;

import java.net.URI;
import java.net.URISyntaxException;

import com.lizongbo.seotijian.util.HttpUtil;
import com.temesoft.google.pr.JenkinsHash;

/**
 * 
 * @see http 
 *      ://toolbarqueries.google.com/search?client=navclient-auto&ch=61070114775
 *      &ie=UTF-8&oe=UTF-8&features=Rank&q=info:618119.com&rnd=
 *      0.3606279264204204
 * @author lizongbo
 * 
 */
public class GooglePageRankCheckRule extends AbstractCheckRule {
	/** 默认pr值 */
	int pageRank = 0;

	public int getPageRank() {
		return pageRank;
	}

	@Override
	public boolean doCheck(URI uri) {
		JenkinsHash jHash = new JenkinsHash();
		long hash = jHash.hash(("info:" + uri).getBytes());
		String prUrl = "http://toolbarqueries.google.com/search?client=navclient-auto&hl=en&"
				+ "ch=6"
				+ hash
				+ "&ie=UTF-8&oe=UTF-8&features=Rank&q=info:"
				+ uri;
		try {
			System.out.println("prUrl=" + prUrl);
			String rs = HttpUtil.httpGet(prUrl);
			System.out.println("rs=" + rs);
			pageRank = Integer.parseInt(rs.split(":")[2].trim());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return false;
	}

	public static void main(String[] args) throws URISyntaxException {
		String urlStr = "http://storyday.com";
		GooglePageRankCheckRule rule = new GooglePageRankCheckRule();
		rule.doCheck(new URI(urlStr));
	}
}
